#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年9月15日

@author: chenyongbing
'''
import sys,os,commands
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]
import logging


def git_checkout(branch=None):
    cmd = 'git checkout %s'%branch
    out = commands.getoutput(cmd)
    print out

def get_branch_and_commit(projectPath = '/data/zhimind',gitPath = '/home/zhima/java/build',commit=None):
    rfile = projectPath+'/README'
    if not os.path.exists(rfile):
        logging.error('file %s not exists.'%(rfile))
        sys.exit()

    for line in open(rfile).read().split('\n'):
        lineList = line.split(',')
        if len(lineList)!=3:continue
        pj_name,pj_ver,pj_commit = lineList
        if pj_name == 'zm-base':
            pj_gitpath = gitPath + '/%s-%s'%(pj_name,pj_ver)
        else:
            pj_gitpath = gitPath +'/%s'%pj_name
            
        self.git_pull()
        if commit!=None:
            self.git_checkout(commit)
        else:
            logging.error('commit must not None')
            sys.exit()


if __name__=='__main__':
    import argparse
    parser = argparse.ArgumentParser(description='args')
    parser.add_argument('-p',metavar="项目路径",required=True)
    